﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace WebView_SSResourceManager
{
    static class EncryptionId
    {
        private static readonly byte[] Iv = Encoding.Default.GetBytes("qЯFGЭШЮУ");
        private static readonly byte[] Key = Encoding.Default.GetBytes("Цy+К2&МZhdђОlКѕЎёЛя^‹Qє");

        public static string Encrypt(Guid id)
        {
            var cryptoProvider = new TripleDESCryptoServiceProvider();
            var encryptor = cryptoProvider.CreateEncryptor(Key, Iv);
            var idBytes = Encoding.Default.GetBytes(id.ToString());
            idBytes = encryptor.TransformFinalBlock(idBytes, 0, idBytes.Count());
            return Encoding.Default.GetString(idBytes);
        }

        public static Guid Decrypt(string encryptId)
        {
            var idBytes = Encoding.Default.GetBytes(encryptId);
            var cryptoProvider = new TripleDESCryptoServiceProvider();
            var decryptor = cryptoProvider.CreateDecryptor(Key, Iv);
            idBytes = decryptor.TransformFinalBlock(idBytes, 0, idBytes.Count());
            var decryptText = Encoding.Default.GetString(idBytes);
            return Guid.Parse(decryptText);
        }
    }
}
